package com.freak.wanandroid.model.system;

import com.freak.httpmanager.callback.SubscriberCallBack;
import com.freak.wanandroid.base.repository.BaseRepository;
import com.freak.wanandroid.bean.SystemClassifyBean;
import com.freak.wanandroid.bean.SystemDetailBean;
import com.freak.wanandroid.net.HttpResultFunc;
import com.freak.wanandroid.util.ToolUtils;

import java.util.List;

import io.reactivex.rxjava3.core.Observable;


public class SystemRepository extends BaseRepository {

    public void getSystem(SubscriberCallBack<List<SystemClassifyBean>> observer) {
        Observable observable = mApiService.getSystemClassify().map(new HttpResultFunc<List<SystemClassifyBean>>());
        addSubscription(observable, observer);
    }

    public void getClassifyDetail(String curPage, String cid,SubscriberCallBack<SystemDetailBean> observer) {
        String page = ToolUtils.subtract(curPage, "1");
        Observable observable = mApiService.getClassifyDetail("article/list/" + page + "/json", cid).map(new HttpResultFunc<SystemDetailBean>());
        addSubscription(observable, observer);
    }

    /**
     * 文章列表中取消收藏
     *
     * @param id
     */
    public void doCancelCollect(int id,SubscriberCallBack<String> observer) {
        Observable observable = mApiService.doCancelCollect(id).map(new HttpResultFunc<String>());
        addSubscription(observable, observer);
    }

    /**
     * 收藏文章
     */
    public void doCollect(int id,SubscriberCallBack<String> observer) {
        Observable observable = mApiService.doCollect(id).map(new HttpResultFunc<String>());
        addSubscription(observable, observer);
    }
}
